package com.example.loginmvvm.musicList

import com.example.loginmvvm.player.domain.Music
import kotlin.concurrent.thread

/*
 * class title: 
 * Author by RenChunLin, Email 18957806320@163.com, Date on 2021/4/19.
 * PS: Not easy to write code, please indicate.
 */
class MusicModel {
    fun loadMusicByPage(page: Int, size: Int, callback: OnMusicLoadResult) {
        val result = arrayListOf<Music>()
        thread {
            for (i in (0 until size)) {
                Thread.sleep(200)
                result.add(Music("音乐的名称$i", "cover 封面 $i", "url==>$i"))
            }
            //数据请求完成
            //通知数据更新
            callback.onSuccess(result)
        }
    }

    interface OnMusicLoadResult {
        fun onSuccess(result: List<Music>)
        fun onError(msg: String, code: Int)
    }
}